package com.tuanbiao.dialog;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.abiao.lib_utils.ScreenUtils;
import com.abiao.lib_utils.SizeUtils;
import com.tuanbiao.R;
import com.tuanbiao.base.action.ToastAction;

/**
 * @author abiao
 * @date 2022/9/9 9:55
 * @description:
 */
public abstract class BaseDialogFragment extends DialogFragment implements ToastAction {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(), container, false);
        initViews(view);
        setStyle(STYLE_NO_TITLE, R.style.BaseDialogTheme);
        return view;
    }

    protected abstract void initViews(View view);

    @Override
    public void onStart() {
        Window window = getDialog().getWindow();
        window.getAttributes().width = ScreenUtils.getAppScreenWidth() - SizeUtils.dp2px(10);
        super.onStart();
    }

    protected abstract int getLayoutId();

    protected String getString(TextView view) {
        return view == null ? "" : view.getText().toString().trim();
    }
}
